﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Informant.UI.Wpf.Converters
{
	public class InverseBooleanConverter : IValueConverter
	{
		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			return ConvertValue(value);
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			return ConvertValue(value);
		}

		/// <summary>
		/// Converts the value.
		/// The same functionality is being performed in both Convert and ConvertBack.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <returns></returns>
		private Object ConvertValue(Object value)
		{
			Object result = Binding.DoNothing;
			if (value != null)
			{
				Boolean boolean;
				if (Boolean.TryParse(value.ToString(), out boolean))
				{
					result = !boolean;
				}
			}
			return result;
		}

		#endregion
	}
}
